package 时间;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class 图形化界面显示时间 {

    public static void main(String[] args) {
        JFrame jf = new JFrame("时间");

        jf.setSize(450, 100);
        jf.setAlwaysOnTop(true);
        jf.setLocationRelativeTo(null);
        jf.setLayout(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//constant 常量

        JLabel jLabel = new JLabel();

        String time = null;
        Font font = new Font("宋体",Font.BOLD,17);
        while (true) {
            init(jf, jLabel, null,font);
        }
    }

    private static void init(JFrame jf, JLabel jLabel,String time,Font font) {

        jf.getContentPane().removeAll();
        //时间对象
        ZonedDateTime zonetime = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        //时间格式器
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒SS毫秒 EE a");
        //System.out.println(dtf.format(zonetime));
        time = dtf.format(zonetime);
        //System.out.println(time);

        jLabel.setText(time);
        jLabel.setBounds(5,0,500,50);
        jLabel.setFont(font);
        jLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
        jf.getContentPane().add(jLabel);

        jf.getContentPane().repaint();

        jf.setVisible(true);
    }
}
